package com.ziyucoding.springboot.labs.lab4.concurrentdemo.example.immutable;

import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

/**
 * 不可变对象示例1
 *
 * @author ziyucoding
 * @date 2022-11-27
 **/
@Slf4j
public class ImmutableExample1 {

    private final static Integer age = 18;

    private final static String name = "Apple";

    private final static Map<String, String> companyNameMap = Maps.newHashMap();

    static {
        companyNameMap.put("apple", "苹果");
        companyNameMap.put("google", "谷歌");
    }

    public static void main(String[] args) {
//        age = 18; // 编译错误
//        name = "google"; // 编译错误
//        companyNameMap = Maps.newHashMap(); // 编译错误
        // 值可以修改
        companyNameMap.put("jd", "京东");
        log.info("{}", companyNameMap.get("apple"));
    }

    private void test(final int userAge) {
//        userAge = 10; // 变量不能再赋值
    }

}
